package com.schoolcloud.share.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.share.dto.ShareSetSaveDTO;
import com.schoolcloud.share.entity.VideoSets;
import com.schoolcloud.share.query.VideoSetQuery;
import com.schoolcloud.share.service.VideoSetsService;
import com.schoolcloud.share.mapper.VideoSetsMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author hongmizfb
* @description 针对表【video_sets(视频合集主表)】的数据库操作Service实现
* @createDate 2025-05-16 18:35:15
*/
@Service
public class VideoSetsServiceImpl extends ServiceImpl<VideoSetsMapper, VideoSets>
    implements VideoSetsService{

    @Override
    public void createVideoSet(ShareSetSaveDTO videoSet) {
        videoSet.setCreateTime(LocalDateTime.now());
        videoSet.setCreatorId(UserContext.getUserToInteger());
        save(videoSet);
    }

    @Override
    public PageDTO<VideoSets> getVideoSetPage(VideoSetQuery query) {
        String title = query.getTitle();
        Page<VideoSets> page = lambdaQuery().like(title != null, VideoSets::getTitle, title)
                .page(query.toMpPage());
        return MpPageUtil.of(page, VideoSets.class);
    }
}
